package com.wontube.smr.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.wontube.client.modle.vo.PagenateInfo;
import com.wontube.client.remote.Remoting;
import com.wontube.smr.web.client.admin.IAdminHandler;


/**
 * tool 控制器
 * 
 * @author hewc@wondershare.cn
 * 
 */
@Controller
@RequestMapping(value = "/tools", method = RequestMethod.GET)
public class ToolController {
	
	@RequestMapping("")
	public void index0(HttpServletRequest request, 
			HttpServletResponse response) throws IOException{	
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/tools/");		
	}
	
	@RequestMapping("/")
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView();
		Remoting<IAdminHandler> remoting = new Remoting<IAdminHandler>();
		IAdminHandler handler = remoting.createService(IAdminHandler.class);
		mv.addObject("websiteItems", handler.selectTool("Website", new PagenateInfo(1, 3)));
		mv.addObject("pcItems", handler.selectTool("Pc", new PagenateInfo(1, 4)));
		mv.addObject("mobileItems", handler.selectTool("Mobile", new PagenateInfo(1, 3)));

		mv.setViewName("tools/tool_index");

		return mv;
	}

	@RequestMapping("/website")
	public void website(HttpServletRequest request, 
			HttpServletResponse response) throws IOException{	
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/tools/");	
	}

	@RequestMapping("/pc")
	public void pc(HttpServletRequest request, 
			HttpServletResponse response) throws IOException{	
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/tools/");	
	}

	@RequestMapping("/mobile")
	public void mobile(HttpServletRequest request, 
			HttpServletResponse response) throws IOException{	
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/tools/");		
	}

	@RequestMapping("/showDetail/{id}")
	public void showDetail(@PathVariable("id") String id, HttpServletRequest request, 
			HttpServletResponse response) throws IOException{	
		response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
		response.sendRedirect(request.getContextPath() + "/tools/");	
	}
}
